package com.hancheng.ordercloud.business.controller;

import com.hancheng.commoncloud.business.entity.dto.IdDTO;
import com.hancheng.commoncloud.business.entity.dto.IdListDTO;
import com.hancheng.commoncloud.framework.result.PageResult;
import com.hancheng.commoncloud.framework.result.Response;
import com.hancheng.commoncloud.framework.util.KafkaSenderUtils;
import com.hancheng.ordercloud.business.entity.dto.OrderDTO;
import com.hancheng.ordercloud.business.entity.dto.OrderInsertDTO;
import com.hancheng.ordercloud.business.entity.vo.OrderVO;
import com.hancheng.ordercloud.business.service.OrderService;
import com.hancheng.ordercloud.feign.service.GoodsFeignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 订单表 Controller
 *
 * @author 韩诚
 * @date 2025/06/22
 */
@Api(tags = "订单表")
@RestController
@RequestMapping("/api/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private KafkaSenderUtils kafkaSenderUtils;

    /**
     * kafka发送消息
     *
     * @return
     */
    @ApiOperation(value = "发送消息", httpMethod = "POST")
    @PostMapping("/sendMessage")
    public Response<Void> sendMessage(String message) {
        kafkaSenderUtils.send("order-events", message);
        return Response.ok();
    }

    /**
     * 分页列表
     *
     * @param orderDTO
     * @return
     */
    @ApiOperation(value = "分页列表", httpMethod = "POST")
    @PostMapping("/getPageList")
    public Response<PageResult<OrderVO>> getPageList(@RequestBody OrderDTO orderDTO) {
        return Response.ok(orderService.getPageList(orderDTO));
    }

    /**
     * 下拉框列表
     *
     * @param orderDTO
     * @return
     */
    @ApiOperation(value = "下拉框列表", httpMethod = "POST")
    @PostMapping("/getList")
    public Response<List<OrderVO>> getList(@RequestBody OrderDTO orderDTO) {
        return Response.ok(orderService.getList(orderDTO));
    }

    /**
     * 明细
     *
     * @param idDTO
     * @return
     */
    @ApiOperation(value = "明细", httpMethod = "POST")
    @PostMapping("/detail")
    public Response<OrderVO> detail(@RequestBody @Valid IdDTO idDTO) {
        return Response.ok(orderService.detail(idDTO));
    }

    /**
     * 新增
     *
     * @param orderInsertDTO
     * @return
     */
    @ApiOperation(value = "新增", httpMethod = "POST")
    @PostMapping("/insert")
    public Response<Void> insert(@RequestBody @Valid OrderInsertDTO orderInsertDTO) {
        orderService.insert(orderInsertDTO);
        return Response.ok();
    }

    /**
     * 批量删除
     *
     * @param idListDTO
     * @return
     */
    @ApiOperation(value = "批量删除", httpMethod = "POST")
    @PostMapping("/deleteBatch")
    public Response<Void> deleteBatch(@RequestBody @Valid IdListDTO idListDTO) {
        orderService.deleteBatch(idListDTO);
        return Response.ok();
    }
}
